$(document).ready(function () {	
	
	/**
	 * 我的开始
	 */
	/**
	 * 事件管理
	 */
	$('.sjgl').click(function () {
		//alert("应急处置");
		//redirectPage("work/zhzrm.jsp");
		//alert("yjcz");
		//setEventPlan2Session();
		//alert("事件管理");
		window.parent.frames['topFrame'].location.href="/ag/work/event_manage_top_only_e.jsp";
		redirectPage("/ag/wzp/event_findById.action?event.EId="+getCookie(eventId));
		//window.parent.frames['mainFrame'].location.href="/ag/wzp/event_edit.action?EId="+eid;
	});
	/**
	 * 指定指挥长
	 */
	$('.zhzrm').click(function () {
		redirectPage("work/zhzrm.jsp");
		//alert("zhzrm");
	});
	
	/**
	 * 指挥长变更
	 *//*
	$('.zhzbg').click(function () {
		redirectPage("work/zhzbg.jsp");
		//alert("zhzrm");
	});*/
	/**
	 * 办结报告
	 */
	$('.bjbg').click(function () {
		//alert("zhzrm");
		redirectPage("/ag/dgm/EventReport.jsp?eventId="+getCookie(eventId));
		//alert("zhzrm");
	});
	/**
	 * 事件详情
	 */
	$('.sjxq').click(function () {
		//alert("事件详情");
		//redirectPage("/ag/dgm/EventReport.jsp?eventId="+getCookie(eventId));
		//alert("zhzrm");
		redirectPage("/ag/wzp/event_findById.action?event.EId="+getCookie(eventId));
	});
	/**
	 * 预案申请
	 */
	$('.yasq').click(function () {
		redirectPage("work/rating.jsp");
		//alert("zhzrm");
	});
	/**
	 * 应急处置
	 */
	$('.yjcz').click(function () {
		//alert("应急处置");
		//redirectPage("work/zhzrm.jsp");
		//alert("yjcz");
		//setEventPlan2Session();
		checkEmergency();
	});
	/////////////////////////////////////////////////////////////////
	/**
	 * 返回上一级
	 * @param {Object} '.event_man_edit'
	 */
	$('.event_man').click(function () {
		//parent.location.href="/ag/wzp/event_man.jsp";
//		$("#topFrame", window.parent.document).attr("src", "/ag/work/event_manage_top.jsp");
		window.location.href="/ag/work/event_manage_top.jsp";
		redirectPage("/ag/wzp/event_findById.action?event.EId="+getCookie(eventId));
//        $('#mainFrame', window.parent.document).attr("src", "wzp/event_findById.action?event.EId="+getCookie(eventId));
	});	
	
	function back(){
		$("#topFrame", window.parent.document).attr("src", "/ag/work/event_manage_top.jsp");
		$('#mainFrame', window.parent.document).attr("src", "wzp/event_findById.action?event.EId="+eid);
	}
	/**
	 * 没用用
	 */
	$('.event_man_edit').click(function () {
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();		
		$('#topFrame', window.parent.document).attr("src", "wzp/event_manage_top.jsp");
        $('#mainFrame', window.parent.document).attr("src", "wzp/event_findById.action?event.EId="+eid);	
	});	
	/**
	 * 没用用
	 */
	$('.event_add').click(function () {
		redirectPage("wzp/event_addByCall.action");
	});	
	/**
	 * 事件管理 没有用到
	 */
	$('.event_manage').click(function () {
		redirectPage("wzp/event_query_start.jsp");
	});	
	/**
	 * 事件修改
	 */
	/*
	$('.sjxg').click(function () {
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		//window.parent.frames['topFrame'].location.href="/ag/wzp/event_edit_top.jsp";
		window.parent.frames['mainFrame'].location.href="/ag/wzp/event_edit.action?EId="+eid;
	});
	*/
	$('.sjxg').click(function () {
		var eid=$("#eid").text();
		//window.parent.frames['topFrame'].location.href="/ag/wzp/event_edit_top.jsp";
		//alert(eid);
		window.location.href="/ag/wzp/event_edit.action?EId="+eid;
	});
	/**
	 * 事件删除
	 */
	$('.sjsc').click(function () {
		var eid=$("#eid").text();
		//var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		if(confirm("确定删除受理单号是"+eid+"的事件？")){
			$.ajax({
  				type: "post",
  				data:{'EId':eid},
 				url: "wzp/event_delete.action",
  				success:function(data){
  					if(data=="true"){
  						alert("删除成功！")
  						//parent.location.href="/ag/work/event_query_start.jsp";
  						//alert("dd");
  						setCookie(eventId,"");
  						//alert(getCookie(eventId));
  						//alert("okok");
  						window.location.href="/ag/work/event_query_start.jsp";
  					}else{
  						alert("删除失败！")
  					}
  				}
  			});
			//parent.location.href="/ag/wzp/event_delete.action?EId="+eid;
		}
	});
	

	
	
	/**
	 * 事件补充 
	 */ 
	$('.sjbc').click(function () {
		$("#addMackupWindow").dialog('open');
		//var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		//var eid=$("#eid").text();
		//alert("vvvvvvvvvvvvv");
		//window.parent.frames['mainFrame'].location.href="/ag/wzp/event_findEventToMackup.action?event.EId="+eid;
		//window.location.href="/ag/wzp/event_findEventToMackup.action?event.EId="+eid;
	});
	/**
	 * 事件补充 备份
	 */ 
	$('.sjbc_bak').click(function () {
		
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		//window.parent.frames['mainFrame'].location.href="/ag/wzp/event_findById.action?event.EId="+eid;
		var strHTML="<div id='smsp' class='faqbg'></div>";
			strHTML+="<div id='subsmsp' class='faqdiv' style='display:none'>";
			strHTML+="<h2>事件补充<span class='close'>关闭</span></h2>";
			strHTML+="<div class='subArea'>受理单号：<span style='color:red;font-size:18'>"+eid+"</span></div>";
			strHTML+="<div class='subArea'><span >补充内容：</span></div>";
			strHTML+="<div class='subArea'><textarea id='mcontent' style='width:420;height:100'></textarea></div>";
			strHTML+="<div class='subArea'>上传附件：<input type='file'/></div>";
			strHTML+="<div ><span style='padding-left:290'><button id='submit' class='submit'>补充</button></span>";
			strHTML+=" <span style='padding-left:10'><button class='submit close'>取 消</button></span></div><br />";
			strHTML+="</div>"
			$("body",window.parent.frames['mainFrame'].document).append(strHTML);
			$("#smsp",window.parent.frames['mainFrame'].document).css({display:"block",height:$(window.parent.frames['mainFrame'].document).height()});
			$("#subsmsp",window.parent.frames['mainFrame'].document).css("display","block");
			window.parent.frames['mainFrame'].document.documentElement.scrollTop=0;
			$(".close",window.parent.frames['mainFrame'].document).click(function(){
				$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  			$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
			});
			$("#submit",window.parent.frames['mainFrame'].document).click(function(){
				var content = $("#mcontent",window.parent.frames['mainFrame'].document).val();
				$.ajax({
  					type: "post",
  					data:{'mackup.tbEvent.EId':eid,'mackup.emContext':content},
 					url: "wzp/eventMackup_save.action",
  					success:function(data){
  						alert(data);
  						$.ajax({
  							type: "post",
  							data:{'EId':eid},
 							url: "wzp/eventMackup_findByEId.action",
  							success:function(data){
  								$("#mackups",window.parent.frames['mainFrame'].document).empty();
  								var strHTML = "";
  								$.each(data.mackups,function(i,n){
  									var j = i + 1;
  									strHTML += "<tr class='trtab'>";
		  							strHTML += "<td class='tdtab2' colspan='3'>";
		  							strHTML += "<span style='float: left; padding-top:20;width:104;text-align:right'>事件补充"+j+"：</span>";
		  							strHTML += "<span class='textAeraRight'>补充人："+n.tbUser.UName+ "   补充时间："+n.emTime.replace(/T/," ");
		  							strHTML += "<span class='textAeraRight'>"+n.emContext+"</span>";
									strHTML += "</span></td></tr>";
								});
								$("#mackups",window.parent.frames['mainFrame'].document).append(strHTML).show();
								$('#mackup_down',window.parent.frames['mainFrame'].document).hide();
								$('#mackup_up',window.parent.frames['mainFrame'].document).show();
  							}
  						});
  						$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  					$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
  					}
				});
			});
	});
	/**
	 * 请求处置建议
	 */
	$('.czjyqq').click(function () {
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		window.parent.frames['mainFrame'].location.href="/ag/wzp/expert_notify.jsp";
	});
	/**
	 * 请求处置建议 旧
	 */
	$('.da_notify_bak').click(function () {
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		var strHTML="<div id='smsp' class='faqbg'></div>";
			strHTML+="<div id='subsmsp' class='faqdiv' style='display:none'>";
			strHTML+="<h2>请求处置建议<span class='close'>关闭</span></h2>";
			strHTML+="<div class='subArea'>受理单号：<span style='color:red;font-size:18'>"+eid+"</span></div>";
			strHTML+="<div class='subArea'>手机号码：<span id='phone'>13806812345</span></div>";
			strHTML+="<div class='subArea'><span style='float: left;'>短信内容：</span><textarea id='smsContent' style='width:230;height:100'></textarea></div>";
			strHTML+="<div ><span style='padding-left:210'><button id='submit' class='submit'>发送</button></span>";
			strHTML+=" <span style='padding-left:10'><button class='submit close'>取 消</button></span></div><br />";
			strHTML+="</div>"
			$("body",window.parent.frames['mainFrame'].document).append(strHTML);
			$("#smsp",window.parent.frames['mainFrame'].document).css({display:"block",height:$(window.parent.frames['mainFrame'].document).height()});
			$("#subsmsp",window.parent.frames['mainFrame'].document).css("display","block");
			window.parent.frames['mainFrame'].document.documentElement.scrollTop=0;
			$(".close",window.parent.frames['mainFrame'].document).click(function(){
				$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  			$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
			});
			$("#submit",window.parent.frames['mainFrame'].document).click(function(){
				var phone = $("#phone").text();
				var sms = $("#smsContent").text();
				alert(sms);
				confirm("短信发送成功！");
				window.location.href="event_man.jsp";
			});
	});
	
	
	$(".adviceApply").click(function(){
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		var ename=$("#eventName",window.parent.frames['mainFrame'].document).text();
		redirectPage("/ag/dgm/findAdviceByType_DGMdisposalAdvice.action?atIdString=0000000000");
	});
	/**
	 * 添加处置建议
	 */
	$('.czjytj').click(function () {
		//var ename=$("#ename",window.parent.frames['mainFrame'].document).text();
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		var strHTML="<div id='smsp' class='faqbg'></div>";
			strHTML+="<div id='subsmsp' class='faqdiv' style='display:none'>";
			strHTML+="<h2>添加处置建议<span class='close'>关闭</span></h2>";
			//strHTML+="<div class='subArea'>事件名称：<span style='color:red;font-size:18'>"+ename+"</span></div>";
			strHTML+="<div class='subArea'>受理单号：<span style='color:red;font-size:18'>"+eid+"</span></div>";
			//strHTML+="<div class='subArea' >代  <input type='text' size='10'/> 录入处置建议（可选填）</div>";
			strHTML+="<div class='subArea'><span style='float: left;'>建议内容：</span><textarea id='smsContent' style='width:320;height:120'></textarea></div>";
			strHTML+="<div ><span style='padding-left:290'><button id='submit' class='submit'>添加</button></span>";
			strHTML+=" <span style='padding-left:10'><button class='submit close'>取 消</button></span></div><br />";
			strHTML+="</div>"
			$("body",window.parent.frames['mainFrame'].document).append(strHTML);
			$("#smsp",window.parent.frames['mainFrame'].document).css({display:"block",height:$(window.parent.frames['mainFrame'].document).height()});
			$("#subsmsp",window.parent.frames['mainFrame'].document).css("display","block");
			window.parent.frames['mainFrame'].document.documentElement.scrollTop=0;
			$(".close",window.parent.frames['mainFrame'].document).click(function(){
				$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  			$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
			});
			$("#submit",window.parent.frames['mainFrame'].document).click(function(){
				//var phone = $("#phone").text();
				var sms = $("#smsContent",window.parent.frames['mainFrame'].document).text();		
				$.ajax({				 
		  			type: "post",
		 			url: "work/MyAdvice_save.action",
		 			data:{
		 				  "EId":eid,"daContent":sms
		 				 },
		  			success:showData
				 });
				confirm("添加成功！");
				//window.location.href="event_man.jsp";
			});
	});
	
	//事件呈批
	$('.sjcp').click(function () {
		//var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		//window.parent.frames['mainFrame'].location.href="/ag/wzp/event_propose.jsp";
		window.parent.frames['mainFrame'].location.href="/ag/work/reportTable.jsp";
		//findReportTable();
	});
	/*
	//呈批审核
	$('.cpsh').click(function () {
		window.parent.frames['mainFrame'].location.href="/ag/work/reportTableCheck.jsp";
	});
	*/
	/**
	 * 呈报 旧
	 */
	$('.event_propose_bak').click(function () {
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		var tbes=$("#tdes",window.parent.frames['mainFrame'].document).text();
		var strHTML="<div id='smsp' class='faqbg'></div>";
			strHTML+="<div id='subsmsp' class='faqdiv' style='display:none'>";
			strHTML+="<h2>呈批<span class='close'>关闭</span></h2>";
			strHTML+="<div class='subArea'>受理单号：<span style='color:red;font-size:18'>"+eid+"</span></div>";
			strHTML+="<div class='subArea' >值班领导：黄宇</div>";
			strHTML+="<div class='subArea' >手机号码：13800138000</div>";
			strHTML+="<div class='subArea'><span style='float: left;'>呈批内容：</span><textarea id='paContent' style='width:320;height:120'></textarea></div>";
			strHTML+="<div class='subArea' ><span id='esSelect'>事件状态：";
			strHTML+="<select name='event.tbEventStatus.tbesId' id='eventStatus' style='width:80'></select></span></div>";
			strHTML+="<div ><span style='padding-left:290'><button id='submit' class='submit'>呈批</button></span>";
			strHTML+=" <span style='padding-left:10'><button class='submit close'>取 消</button></span></div><br />";
			strHTML+="</div>"
			$("body",window.parent.frames['mainFrame'].document).append(strHTML);
			$("#smsp",window.parent.frames['mainFrame'].document).css({display:"block",height:$(window.parent.frames['mainFrame'].document).height()});
			$("#subsmsp",window.parent.frames['mainFrame'].document).css("display","block");
			window.parent.frames['mainFrame'].document.documentElement.scrollTop=0;
			$.ajax({
  				type: "post",
 				url: "wzp/eventBase_getAllEventStatus.action",
  				success:function(data){
  					$.each(data.eventStatuses,function(i,n){
  						if(tbes==n.tbesEventStatus)
  							$("#eventStatus",window.parent.frames['mainFrame'].document).append("<option value="+n.tbesId+" selected>"+n.tbesEventStatus+"</option>");
  						else
  							$("#eventStatus",window.parent.frames['mainFrame'].document).append("<option value="+n.tbesId+" >"+n.tbesEventStatus+"</option>");
					});
  				}
			});	
			$(".close",window.parent.frames['mainFrame'].document).click(function(){
				$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  			$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
			});
			$("#submit",window.parent.frames['mainFrame'].document).click(function(){
				var tbesId = $.trim($("#eventStatus option:selected",window.parent.frames['mainFrame'].document).val());
				var phone = $("#phone",window.parent.frames['mainFrame'].document).text();
				var paContent = $("#paContent",window.parent.frames['mainFrame'].document).text();
				alert(tbesId);
				$.ajax({
  					type: "post",
  					data: {'propose.tbEvent.EId':eid,'propose.paContent':paContent,
  							'tbesId':tbesId},
 					url: "wzp/propose_save.action",
  					success:function(data){
  						alert(data);
  					}
				});	
				$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  			$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
			});
	});
	/**
	 * 应急措施 旧
	 */
	$('.event_emergency').click(function () {
		/*
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		var strHTML="<div id='smsp' class='faqbg'></div>";
			strHTML+="<div id='subsmsp' class='faqdiv' style='display:none'>";
			strHTML+="<h2>通知值班领导<span class='close'>关闭</span></h2>";
			strHTML+="<div class='subArea'>受理单号：<span style='color:red;font-size:18'>"+eid+"</span></div>";
			strHTML+="<div class='subArea' >值班领导：张子龙</div>";
			strHTML+="<div class='subArea' >手机号码：13800138000</div>";
			strHTML+="<div class='subArea'><span style='float: left;'>通知内容：</span><textarea id='smsContent' style='width:320;height:120'></textarea></div>";
			strHTML+="<div ><span style='padding-left:290'><button id='submit' class='submit'>通知</button></span>";
			strHTML+=" <span style='padding-left:10'><button class='submit close'>取 消</button></span></div><br />";
			strHTML+="</div>"
			$("body",window.parent.frames['mainFrame'].document).append(strHTML);
			$("#smsp",window.parent.frames['mainFrame'].document).css({display:"block",height:$(window.parent.frames['mainFrame'].document).height()});
			$("#subsmsp",window.parent.frames['mainFrame'].document).css("display","block");
			window.parent.frames['mainFrame'].document.documentElement.scrollTop=0;
			$.ajax({
  				type: "post",
 				url: "wzp/eventBase_getAllEventStatus.action",
  				success:function(data){
  					$.each(data.eventStatuses,function(i,n){
  						//$("#eventStatus",window.parent.frames['mainFrame'].document).append("<option value="+n.tbesId+">"+n.tbesEventStatus+"</option>");
					});
  				}
			});	
			$(".close",window.parent.frames['mainFrame'].document).click(function(){
				$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  			$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
			});
			$("#submit",window.parent.frames['mainFrame'].document).click(function(){
				var phone = $("#phone").text();
				var sms = $("#smsContent").text();
				confirm("短信发送成功！");
				window.location.href="/ag/do/processStart_processEventStart.action?eventId="+eid;
			});
		*/
		var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		window.parent.frames['mainFrame'].location.href="/ag/lzm/wzp.jsp";
	});
	$('#ImgArrow').toggle(
		function(){
			$(this).attr("src","images/switch_down.gif");
			$('#topFrame', window.parent.document).attr("rows", "0,6,*"); 
			//parent.centerFrameSet.rows="0,6,*";
		},
		function(){
			//parent.centerFrameSet.rows="75,6,*";
			$('#topFrame', window.parent.document).attr("rows", "75,6,*"); 
			$(this).attr("src","images/switch_up.gif"); 
		}
	);
});

/**
 * 实现页面的定向
 * @param url 传入定向的目标URL
 */
function redirectPage(url){
   $('#mainFrame', window.parent.document).attr("src", url);
}

function findReportTable(){	
	var timestamp = Date.parse(new Date());
	//$.get("/do/processStart_processEventStartByPlan.action?ts="+timestamp+"&eventId="+getCookie(eventId),null,findReportTableRst);
}

function findReportTableRst(data){
	if(data.ajaxRst=="no"){
		//window.parent.location.href="/zrt/loadPlanStep.action";
		redirectPage("/ag/work/reportTable.jsp");
		//window.parent.frames['mainFrame'].location.href="/ag/work/reportTable.jsp";
	}else{
		redirectPage("/ag/work/reportTableCheck.jsp");
	}
}

function showData(data){
	if(data.ajaxRST=='1'){
		alert("保存成功");
	}else{
		alert("save sched failed!");
	}
}